#include "pointMotion.h"


//
// point to point collision
//
short caseMove;	  //for two-point collision
short case3Move;  //for three point collision
long colisionPointFlag=0;
int a, b;



int maxSpeed (void)
{
	short max;
	if (points[0].speed >= points[1].speed)
		max = points[0].speed;
	else 
		max = points[1].speed ;

	if (max < points[2].speed)
		max =  points[2].speed;

	return max;
	

}
/*
void setFlag (void)
{
 														// when they are symmetric	
															// and the are in conflict for free cell	
   if (pointsNext[2]==1 && pointsNext[5]==0)
   caseMove ^= 0x01;
   if (pointsNext[2]==0 && pointsNext[5]==1)
   caseMove ^= 0x02;
   if (pointsNext[2]==1 && pointsNext[8]==0)
   caseMove ^= 0x04;
   if (pointsNext[2]==0 && pointsNext[8]==1)
   caseMove ^= 0x08;
   if (pointsNext[5]==1 && pointsNext[8]==0)
   caseMove ^= 0x10;
   if (pointsNext[5]==0 && pointsNext[8]==1)
   caseMove ^= 0x20;
  

}

int point2pointColisionFreeCell(void)						// point to point collision 
{	
 

	if(pointsNext[0] == pointsNext[3] && pointsNext[1]==pointsNext[4] )		 // point1 to point2 collision
																			 //
	{  
	
		if(casemove&0x01)
			colisionPointFlag ^= 0x01;
		if(casemove&0x02)
			colisionPointFlag ^= 0x02;
		if(casemove&0x03)
			colisionPointFlag ^= 0x03;
		
								 
	}


	if(pointsNext[0] == pointsNext[6] && pointsNext[1]==pointsNext[7] )		 // point1 to point3 collision
																			 //
	{
		if(casemove&0x04)
			colisionPointFlag ^= 0x04;
		if(casemove&0x08)
			colisionPointFlag ^= 0x08;
		if(casemove&0x0C)
		    colisionPointFlag ^= 0x0C;
		
								 
	}
  

	if(pointsNext[3] == pointsNext[6] && pointsNext[4]==pointsNext[7] )		 // point2 to point3 collision
																			 //
	{
		if(casemove&0x10)
		colisionPointFlag ^= 0x10;
		if(casemove&0x20)
		colisionPointFlag ^= 0x20;
		if(casemove&0x30)
		colisionPointFlag ^= 0x30;
								 
	}

	 if (colisionPointFlag >0 && colisionPointFlag <=48 )
	return colisionPointFlag;
	else
	return 0;
}




int PPCollisionAsymetric (void)
{


 	 if( abs(points[0].x - points[1].x)== 1)					// p1 hits p2 diagonal
	 {
	 	if (abs (pointsNext[0] - pointsNext[3]) == 1 )
		{
			if (points[0].move !=  points[1].move)
			{
			 	if(casemove&0x01)
				colisionPointFlag ^= 0x40;
				if(casemove&0x02)
				colisionPointFlag ^= 0x80;
				if(casemove&0x03)
				colisionPointFlag ^= 0xC0;
				
			}
	 	  }
	 }


	 if(points[0].y - points[1].y	== -1 || points[0].y - points[1].y ==1)            // p2 hits p1 diagonal
	 {
	 	if ( abs(pointsNext[1] - pointsNext[4])== 1)
		{
			if (points[0].move !=  points[1].move)
			{
		    	if(casemove&0x01)
				colisionPointFlag ^= 0x40;
				if(casemove&0x02)
				colisionPointFlag ^= 0x80;
				if(casemove&0x03)
				colisionPointFlag ^= 0xC0;
			}
	 	  }
	 }



	 	 if(points[0].x - points[2].x	== -1 || points[0].x - points[2].x ==1)				// p1 hits p3 diagonal
	 {
	 	if ( abs( pointsNext[0]-pointsNext[6])== 1)
		{
			if (points[0].move !=  points[2].move)
			{
			 	if(casemove&0x04)
				colisionPointFlag ^= 0x100;
				if(casemove&0x08)
				colisionPointFlag ^= 0x200;
				if(casemove&0x0C)
				colisionPointFlag ^= 0x300;
			}
	 	  }
	 }


	 if(points[0].y - points[2].y	== -1 || points[0].y - points[2].y ==1)                // p3 hits p1 diagonal
	 {
	 	if ( abs(pointsNext[1] - pointsNext[7]) == 1)
		{
			if (points[0].move !=  points[2].move)
			{

			 	if (points[0].move ==  points[2].move)
				{
				if(casemove&0x04)
					colisionPointFlag ^= 0x100;
				if(casemove&0x08)
					colisionPointFlag ^= 0x200;
				if(casemove&0x0C)
					colisionPointFlag ^= 0x300;
			}
	 	  }
	 }


 	 if(points[1].x - points[2].x	== -1 || points[1].x - points[2].x ==1)         // p2 hits p3 diagonal
	 {
	 	if ( abs(pointsNext[3] - pointsNext[6]) == 1)
		{
			if (points[1].move !=  points[2].move)
			{
				if(casemove&0x10)
					colisionPointFlag ^= 0x400;
				if(casemove&0x20) 
					colisionPointFlag ^= 0x800;
				if(casemove&0x30)
					colisionPointFlag ^= 0xC00;

			}
	 	  }
	 }


	 if(points[1].y - points[2].y	== -1 || points[1].y - points[2].y ==1)        // p2 hits p2 diagonal
	 {
	 	if ( abs(pointsNext[4] - pointsNext[7]) == 1)
		{
			if (points[1].move !=  points[2].move)
			{
				if(casemove&0x10)
					colisionPointFlag ^= 0x400;
				if(casemove&0x20) 
					colisionPointFlag ^= 0x800;
				if(casemove&0x30)
					colisionPointFlag ^= 0xC00;

			}
	 	  }
	 }


	   if (	colisionPointFlag >=0x01 && colisionPointFlag<=0xC00)
	   return colisionPointFlag ;
	   else
	   return 0;
} 


 
int point2pointColisionNeighbours(void)							// point to point collision	 when they are symmetric and															 	
															// they are neighbours and there is no free cell between them	
//
{
	short i;
	//if (pointNext[2]==1 && pointNext[5]==1)
 
	 
	if(pointsNext[0] == points[1].x  && pointsNext[1]==points[1].y )		 // point1 to point2 collision
																			 //	  point1 New Position with present point2
	{
					if(casemove&0x01)
					colisionPointFlag ^= 0x1000;
					if(casemove&0x02)
					colisionPointFlag ^= 0x2000;
					if(casemove&0x03)
					colisionPointFlag ^= 0x3000;
		 
								 
	}
	if(points[0].x ==pointsNext[3]  && points[0].y==pointsNext[4])		  // point2 New Position with present point1

 	{
	 			if(casemove&0x01)
					colisionPointFlag ^= 0x4000;
				if(casemove&0x02) 
					colisionPointFlag ^= 0x8000;
				if(casemove&0x03)
					colisionPointFlag ^= 0xC000;
							 
	}


	if(pointsNext[0] == points[2].x  && pointsNext[1]==points[2].y )		 // point1 to point3 collision
																			 //	  point1 New Position with present point2
	{
				if(casemove&0x04)
					colisionPointFlag ^= 0x10000;
				if(casemove&0x08)
					colisionPointFlag ^= 0x20000;
				if(casemove&0x0c)
					colisionPointFlag ^= 0x30000;
								 
	}
	if(points[0].x ==pointsNext[6]  && points[0].y==pointsNext[7])		  // point3 New Position with present point1

	{
				if(casemove&0x04)
					colisionPointFlag ^= 0x40000;
				if(casemove&0x08)
					colisionPointFlag ^= 0x80000;
				if(casemove&0x0C)
					colisionPointFlag ^= 0xC0000;
								 
	}


	if(pointsNext[3] == points[2].x  && pointsNext[4]==points[2].y )		 // point2 to point3 collision
																				 //	  point2 New Position with present point2
		{
				if(casemove&0x10)
					colisionPointFlag ^= 0x100000;
				if(casemove&0x20)
					colisionPointFlag ^= 0x200000;
				if(casemove&0x30)
					colisionPointFlag ^= 0x300000;
								 
		}
	if(points[1].x ==pointsNext[6]  && points[1].y==pointsNext[7])		  // point3 New Position with present point2

	{
				if(casemove&0x10)
					colisionPointFlag ^= 0x400000;
				if(casemove&0x20)
					colisionPointFlag ^= 0x800000;
				if(casemove&0x30)
					colisionPointFlag ^= 0xC00000;
								 
	}





	 
		if(colisionPointFlag>=0x1000 && colisionPointFlag<=0xC00000 )
			return colisionPointFlag;


	return 0;
}
*/

// *****************************************************
// THREE POINTS COLLISION
// *****************************************************


int P3ColisionCase3Move (void)   // case 1 when three point are in conflict for free cell
{
	  
	
  if (colisionPointFlag & 0x33)
		return 	colisionPointFlag;
	else
		return 0;


}


									// FUNKCIITE CORNER I CORNER_FREECELL SE IZVIKAVAT SLED ALL LINE IN THE SAME !!!
									// INACHE SA VAZMOJNI GRESHKI
									// VAZMOJNO RAZSHIRENIE NA CHEKA S UKAZVANE NA POSOKATA  



int  Corner_FreeCell (void)                   // ONE POINT HITS  ONE OF TWO POINTS WHO ARE IN CONFLICT IF FREE CELL

	//case 3
	//	if (pointsNext[0] == pointsNext[3] && pointsNext[1]== pointsNext[4] ) //when point 1 and 2 colision for free cell
	//		if(pointsNext[6] == points[0].x && pointsNext[7]==points[0].y)		  // when point 3 hit  point  1
				 
				 
		//if (colisionPointFlag & 0xC0003)
		if (pointColisionFlag & 0x50 == 0x50)	
			return 	pointColisionFlag;


//		if (pointsNext[0] == pointsNext[3] && pointsNext[1]== pointsNext[4] ) //when point 1 and 2 colision for free cell
//			if(pointsNext[6] == points[1].x && pointsNext[7]==points[1].y)		  // when point 3 hit  point  2
			 
				 
//		if (colisionPointFlag & 0xC00003)
		if (pointColisionFlag & 0x60 == 0x60)	
			return 	pointColisionFlag;
	 



//		if (pointsNext[0] == pointsNext[6] && pointsNext[1]== pointsNext[7] ) //when point 1 and 3 colision for free cell
//			if(pointsNext[3] == points[0].x && pointsNext[4]==points[0].y)		  // when point 2 hit  point  1
				 
				 
	 
//		if (colisionPointFlag & 0xC00C)
		if (pointColisionFlag & 0x84 == 0x84)	
			return 	pointColisionFlag;



//		if (pointsNext[0] == pointsNext[6] && pointsNext[1]== pointsNext[7] ) //when point 1 and 3 colision for free cell
//			if(pointsNext[3] == points[2].x && pointsNext[4]==points[2].y)		  // when point 2 hit  point  3
			 
				 
//		if (colisionPointFlag & 0x30000C)
		if (pointColisionFlag & 0x86 == 0x86)	
			return 	pointColisionFlag;




//		if (pointsNext[3] == pointsNext[6] && pointsNext[4]== pointsNext[7] ) //when point 2 and 3 colision for free cell
//			if(pointsNext[0] == points[1].x && pointsNext[1]==points[1].y)		  // when point 1 hit  point  2
				 
				 
//		if (colisionPointFlag & 0x3030)
		if (pointColisionFlag & 0x0101 == 0x0101)	
			return 	pointColisionFlag;
	


//		if (pointsNext[3] == pointsNext[6] && pointsNext[4]== pointsNext[7] ) //when point 2 and 3 colision for free cell
//			if(pointsNext[0] == points[2].x && pointsNext[1]==points[2].y)		  // when point 1 hit  point  3
			 
				 
//		if (colisionPointFlag & 0x30030)
		if (pointColisionFlag & 0x0102 == 0x0102)	
			return 	pointColisionFlag;

	
		return 0;

		// end of case 3
}

	
int  Corner(void)                   // ONE POINT HITS  ONE OF TWO POINTS WHO ARE IN CONFLICT
{

	
	if (pointColisionFlag & 0x21 == 0x21 )										//when point 1 and 3 hit point 2
		return 	pointColisionFlag;
//	else
	if (pointColisionFlag & 0x14 == 0x14 )										//when point 2 and 3 hit point 1
		return 	pointColisionFlag;
//	else
	if	 (pointColisionFlag & 0x0A == 0x0A )								    //when point 1 and 2 hits point 3
		return 	pointColisionFlag;
		else
	return 0;

}


	//tryin' to check for case 5
	// 1 i 2 se nacepvate diagonalno, 3 gi natrisa m/u pixelite
int CollisionPixelBound (void)
{

	/*	if(abs(points[0].x - points[2].x == 1) && abs(points[1].y - points[2].y) == 1 )
			if(abs(points[1].x - pointNext[6]) == 1 && abs(points[0].y - pointNext[7]) == 1 )
				if (colisionPointFlag & 0x3000)
					return 	colisionPointFlag;   */
	
		if(pointCNConditionFlag&0x102==0x102 && pointMixedConditionFlag&0x120000==0x120000)
			if(pointColisionFlag & 0x05)
			{
			}


	 //razmenqme x i y
	 			 
	/*	if(abs(points[0].y - points[2].y) == 1 && abs(points[1].x - points[2].x)==1)
			  	if(abs(points[1].y - pointNext[7]) == 1 && abs(points[0].x - pointNext[6]) == 1)
					if (colisionPointFlag & 0x3000)
					  return 	colisionPointFlag; */
		if(pointCNConditionFlag&0x0C==0x0C && pointMixedConditionFlag&0x810000==0x810000)
			if(pointColisionFlag & 0x05)
			{
			}


	// 1 i 3 se nacepvat diagonalno, 2 gi nacepva m/u pixelite
				 
	/*	if(abs(points[0].x - points[1].x == 1) && abs(points[2].y - points[1].y) == 1 )
			  	if(abs(points[0].x - pointNext[3]) == 1 && abs(points[2].y - pointNext[4]) == 1 )
					if (colisionPointFlag & 0xC0000)
					  return 	colisionPointFlag; */
		if(pointCNConditionFlag&0x0C==0x0C && pointMixedConditionFlag&0x2100==0x2100)
			if(pointColisionFlag & 0x12)
			{
			}



	//obryshtame po x i y
 			 
	/*	if(abs(points[0].y - points[1].y == 1) && abs(points[2].x - points[1].x) == 1 )
			  	if(abs(points[0].y - pointNext[4]) == 1 && abs(points[2].x - pointNext[3]) == 1 )
					if (colisionPointFlag & 0xC0000)
					 return 	colisionPointFlag;  */
		if(pointCNConditionFlag&0x44==0x44 && pointMixedConditionFlag&0x1200==0x1200)
			if(pointColisionFlag & 0x12)
			{
			}



	// 2 i 3 se nacepvat diagonalni, 1 gi udrq m/u pixelite
			 
	/*	if(abs(points[1].x - points[0].x == 1) && abs(points[2].y - points[0].y) == 1 )
			  	if(abs(points[1].x - pointNext[0]) == 1 && abs(points[2].y - pointNext[1]) == 1 )
					if (colisionPointFlag & 0xC00000)
					  return 	colisionPointFlag; */
		if(pointCNConditionFlag&0x81==0x81 && pointMixedConditionFlag&0x24==0x24)
			if(pointColisionFlag & 0x28)
			{
			}



	//obryshtame x i y
	  		 
	/*	if(abs(points[1].y - points[0].y == 1) && abs(points[2].x - points[0].x) == 1 )
			  	if(abs(points[1].y - pointNext[1]) == 1 && abs(points[2].x - pointNext[0]) == 1 )
					if (colisionPointFlag & 0xC00000)
					 return 	colisionPointFlag; */
		if(pointCNConditionFlag&0x42==0x42 && pointMixedConditionFlag&0x12==0x12)
			if(pointColisionFlag & 0x28 )
			{
			}
		

 		


				return 0;
}



int AllPointsInSame_FreeCell(void)  // all points in the same line or diagonal with free space between two of them
//checking for case 6
{	

//1 i 2 edno s/u drugo, 3 natrisa otzade 1
	
	   		//when point 2 and 3 hit point 1
		  if(points[0].move !=  points[1].move && points[0].move ==  points[2].move)
			  	//if (pointColisionFlag & 0xC0003 )
				if (pointColisionFlag & 0x50 == 0x50)
					return 	pointColisionFlag;
		  
	 //1 i 2 edno s/u drugo, 3 natrisa otzade 2
	      if(points[0].move !=  points[1].move && points[1].move ==  points[2].move)
//			   if (colisionPointFlag & 0xC00003 )
			if (pointColisionFlag & 0x21 == 0x21)
				return 	pointColisionFlag;


	//1 i 3 edno s/u drugo, 2 natrisa otzade 1
		 if(points[0].move !=  points[2].move && points[0].move ==  points[1].move)
//			 if (colisionPointFlag & 0xC0C0 )
			if (pointColisionFlag & 0x84 )
			return 	pointColisionFlag;

   	//1 i 3 edno s/u drugo, 2 natrisa otzade 3
	
		  if(points[0].move !=  points[2].move && points[1].move ==  points[2].move)
			  //if (colisionPointFlag & 0x3000C0 )
			  if (pointColisionFlag & 0x88 )
		  	return 	pointColisionFlag;


   	//2 i 3 edno s/u drugo, 1 natrisa otzade 2
	
	  
		  if(points[1].move !=  points[2].move && points[0].move ==  points[1].move)
			 //  if (colisionPointFlag & 0x30030 )
			   if (pointColisionFlag & 0x010101 )
		  	return 	pointColisionFlag;

	//2 i 3 edno s/u drugo, 1 natrisa otzade 3

	  
		  if(points[1].move !=  points[2].move && points[0].move ==  points[2].move)
			  // if (colisionPointFlag & 0x300C0 )
			   if (pointColisionFlag & 0x010102 )
		  	return 	pointColisionFlag;

		return 0;

}

int AllPointsInSame(void)                                   // All points in  the same line or diagonal without free cell
{

	// all points in the same line or diagonal without free space between two of them
		  //case 7
	

	   	//1 i 2 edno s/u drugo, 3 natrisa otzade 1
		//if (colisionPointFlag & 0xCC000)
		if (pointColisionFlag & 0x14 == 0x14 )
	      if(points[0].move !=  points[1].move && points[0].move ==  points[2].move)
		   return 	pointColisionFlag;;

		 //1 i 2 edno s/u drugo, 3 natrisa otzade 2
//	        if (colisionPointFlag & 0xC0C000)
	   if (pointColisionFlag & 0x24 == 0x24 )
	      if(points[0].move !=  points[1].move && points[1].move ==  points[2].move)
		  	return 	pointColisionFlag;


		//1 i 3 edno s/u drugo, 2 natrisa otzade 1

	   //if(colisionPointFlag & 0xCC000)
	   if (pointColisionFlag & 0x14 == 0x14 )
	      if(points[0].move !=  points[2].move && points[0].move ==  points[1].move)
		  return pointColisionFlag;


	  	//1 i 3 edno s/u drugo, 2 natrisa otzade 3

	   //if (colisionPointFlag & 0x3C0000) 
	   if (pointColisionFlag & 0x28 == 0x28 )  
		 if(points[0].move !=  points[2].move && points[1].move ==  points[2].move)
		   return pointColisionFlag;

	  
	  //2 i 3 edno s/u drugo, 1 natrisa otzade 2

	  // if ( colisionPointFlag & 0x330000 )
	   if (pointColisionFlag & 0x0A == 0x0A )
	      if(points[1].move !=  points[2].move && points[0].move ==  points[1].move)
		  return pointColisionFlag;


		//2 i 3 edno s/u drugo, 1 natrisa otzade 3
	 
	   //if(colisionPointFlag & 0xC30000)
	    if (pointColisionFlag & 0x22 == 0x22 )
	      if(points[1].move !=  points[2].move && points[0].move ==  points[2].move)
		  return pointColisionFlag;


	//reversnato
 
	  // if (colisionPointFlag & 0xC3000)
	   if (pointColisionFlag & 0x11 == 0x11 )
	      if(points[0].move !=  points[1].move && points[0].move ==  points[2].move)
		  return pointColisionFlag;

	 //1 i 2 edno s/u drugo, 3 natrisa otzade 2
 
    //if (colisionPointFlag & 0xC03000)
	if (pointColisionFlag & 0x21 == 0x21)
	      if(points[0].move !=  points[1].move && points[1].move ==  points[2].move)
		  return pointColisionFlag;


	// 1 i 3 edno s/u drugo, 2 natrisa otzade 1
 
	   //if (colisionPointFlag & 0x3C000)
	   if (pointColisionFlag & 0x03 == 0x03)
	      if(points[0].move !=  points[2].move && points[0].move ==  points[1].move)
		  return pointColisionFlag;


	//1 i 3 edno s/u drugo, 2 natrisa otzade 3
 
	   //if (colisionPointFlag & 0x330000)
	   if (pointColisionFlag & 0x0A == 0x0A)
	      if(points[0].move !=  points[2].move && points[1].move ==  points[2].move)
		  return pointColisionFlag;



	//2 i 3 edno s/u drugo, 1 natrisa otzade 2

	 //  if (colisionPointFlag & 0x303000)
	   if (pointColisionFlag & 0x09 == 0x09)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[1].move)
		  return pointColisionFlag;

	 	//2 i 3 edno s/u drugo, 1 natrisa otzade 3
//	 if ( colisionPointFlag & 0x330000)
	 if (pointColisionFlag & 0x0A == 0x0A)
		   if(points[1].move !=  points[2].move && points[0].move ==  points[2].move)
		   return pointColisionFlag;
		  

	return 0;	  
		  
		  

}


		// case 2
int  AnyPointHitsOtherWithDifferentDirection (void)
{


	if(points[0].move !=  points[1].move && points[1].move != points[2].move && points[0].move !=  points[2].move)
		{
	 

		  	//if (colisionPointFlag & 0x303000)								  
			if (pointColisionFlag & 0x09 == 0x09)					//1 i 2 po diagonal
			return pointColisionFlag;							  // point 2 hit point 3

		
			//if (colisionPointFlag && 0xC30000)					   			
			if (pointColisionFlag & 0x22 == 0x22 )					 //1 i 3 po diagonal
			return pointColisionFlag;					         	 // point 3 hit point 2

			//if (colisionPointFlag && 0xC0C000)								     
		    if (pointColisionFlag & 0x24 == 0x24 )					//2 i 3 po diagonal
			return pointColisionFlag;					         	 // point 2 hit point 1
 

			//if (colisionPointFlag && 0x3C000)									 	
			if (pointColisionFlag & 0x21 == 0x21)						//1 i 2 po diagonal
			return pointColisionFlag;								   	// point 1 hit point 3


			//if (colisionPointFlag && 0xC3000)									 	
			if (pointColisionFlag & 0x11 == 0x11 )						//1 i 3 po diagonal
			return pointColisionFlag;									// point 1 hit point 2

		  			  
			//if (colisionPointFlag && 0x3C0000)
			if (pointColisionFlag & 0x28 == 0x28 )  			         //2 i 3 po diagonal
			return pointColisionFlag;									 // point 3 hits point 1
		 	

		}
		else
		return 0;

}


int  TwoPointHitsOtherWithTwoDifferentDirection(void)
{

	 
		if(points[0].move !=  points[1].move && points[1].move != points[2].move)
			//if (colisionPointFlag & 0x303000)								 
			if (pointColisionFlag & 0x09 == 0x09)					 //1 i 2 po diagonal
			return colisionPointFlag;							  // point 2 hit point 3

		if(points[0].move !=  points[2].move && points[1].move != points[2].move)
			//if (colisionPointFlag && 0xC30000)					     
		   if (pointColisionFlag & 0x22 == 0x22 )						//1 i 3 po diagonal
			return pointColisionFlag;						         	 // point 3 hit point 2

		if(points[0].move !=  points[1].move && points[1].move != points[2].move)
			//if (colisionPointFlag && 0xC0C000)					     
		    if (pointColisionFlag & 0x24 == 0x24 )						//2 i 3 po diagonal
			return pointColisionFlag;						         	 // point 2 hit point 1
 
		if(points[0].move !=  points[1].move && points[0].move != points[2].move)
			//if (colisionPointFlag && 0x3C000)						 	
			if (pointColisionFlag & 0x21 == 0x21)						//1 i 2 po diagonal
			return pointColisionFlag;								   	// point 1 hit point 3

		if(points[0].move !=  points[1].move && points[0].move != points[2].move)
			//if (colisionPointFlag && 0xC3000)						 	
			if (pointColisionFlag & 0x11 == 0x11 )						//1 i 3 po diagonal
			return pointColisionFlag;									// point 1 hit point 2

		if(points[0].move != points[2].move && points[1].move !=  points[2].move) 			  
			//if (colisionPointFlag && 0x3C0000)						  
			if (pointColisionFlag & 0x28 == 0x28 )  			         //2 i 3 po diagonal
			return pointColisionFlag;									 // point 3 hits point 1
		 	
	 
		else
		return 0;

}
	  //end of case 2


	// case 8

int TwoPointsHitThirdByDiagonal(void)
{

  // if (colisionPointFlag & 0x330000)
   if (pointColisionFlag & 0x0A == 0x0A)
	//if ( abs(points[0].x - points[1].x) == 2 && abs(points[0].y - points[1].y) == 2 )
	if(pointCNConditionFlag & 0x41 == 0x41; 
	return pointColisionFlag;


  //if (colisionPointFlag & 0xC03000)
  if (pointColisionFlag & 0x21 == 0x21)
	//if ( abs(points[0].x - points[2].x) == 2 && abs(points[0].y - points[2].y) == 2 )
	if(pointCNConditionFlag & 0x82 == 0x82; 
	return colisionPointFlag;

 // if (colisionPointFlag & 0x3C0000)
  if (pointColisionFlag & 0x28 == 0x28 ) 
	if ( abs(points[1].x - points[2].x) == 2 && abs(points[1].y - points[2].y) == 2 )
	if(pointCNConditionFlag & 0x0104 == 0x0104;
	return colisionPointFlag;
	else

	return 0;

		
}
	

void simulation (void)
{


}

void setCollisionFlag()
{

	
	if (colisionPointFlag&0x03 !=0 )
	{  a=0;
	   b=1;
	
	}														
	
	if(colisionPointFlag& 0x0C !=0)
	{
		a=0;
		b=2;
 
	}

	if(colisionPointFlag& 0x30 !=0 )
	{
		a=1;
		b=2;
	 
	}


	if (colisionPointFlag&0xC0 !=0 )
	{  a=0;
	   b=1;
	
	}														
	
	if(colisionPointFlag& 0x300 !=0)
	{
		a=0;
		b=2;
 
	}

	if(colisionPointFlag& 0xC00 !=0 )
	{
		a=1;
		b=2;
	 
	}

	
	if(colisionPointFlag& 0x3000 !=0 )
	{
		a=1;
		b=2;
	 
	}


	if(colisionPointFlag& 0xC000 !=0 )
	{
		a=2;
		b=1;
	 
	}
	
	if(colisionPointFlag& 0x30000 !=0 )
	{
		a=1;
		b=3;
	 
	}

	if(colisionPointFlag& 0xC0000 !=0 )
	{
		a=3;
		b=1;
	 
	}

		if(colisionPointFlag& 0x300000 !=0 )
	{
		a=2;
		b=3;
	 
	}

	if(colisionPointFlag& 0xC00000 !=0 )
	{
		a=3;
		b=2;
	 
	}
}



void setCollisionFlag()
{

	
	if (colisionPointFlag&0x0F )       
	{
		a=1;
		b=2;
		c=3;
	}

	


// Undefined oldposition abd systemflag
void SetSystemFlag (void )
{
	 oldposition[0]=points[a].x;
	 oldposition[1]=points[a].y;
	 oldposition[2]=points[b].x;
	 oldposition[3]=points[b].y;
	 oldposition[4]=points[c].x;
	 oldposition[5]=points[c].y;
	 systemflag ^= 0x04;
}
void revert3(void)
{
	 	 pointRevertLaw(&points[0]);
		 pointRevertLaw(&points[1]);
	     pointRevertLaw(&points[2]);
}

void point2ColisionSolveSymetric_FreeCell(void)		   // colllision solve for SYMETRIC FREE CELL AND  SYMETRIC  NEIGHBORS
										// FOR SYMETRIC FREE CELL USE SIMULATION
										 // have to use simulation 
{
 // USING UNDEFINED VARIABLE SYSTEMFLAG AND ARRAY THAT KEEP OLD POSITION FOR A AND B
// kratyk variant
	if ( point2pointColisionFreeCell())
	{
		     setCollisionFlag()
			 pointRevertLaw(&points[a]);
			 pointRevertLaw(&points[b]);
			 
	}

}


void point2ColisionNeighboursSolve(void)		   // colllision solve when points are neighbours
										 // have to use simulation 
{
 
 short x,y;



// kratyk variant                                                   
	 if (point2pointColisionNeighbours() )                          // when neighbbours are symetric 
	 {
		setCollisionFlag()
	x =	points[a].move - > aplToX * 	-1;
	y =	points[a].move - > aplToY * 	-1;
		if ( x == points[b].move - > aplToX  && y == points[b].move - > aplToY )  
			 pointRevertLaw(&points[a]);
			 pointRevertLaw(&points[b]);
	}
	 else
	if (abs (points[a].x - points[b].x)== 0   ||  abs (points[a].y - points[b].y)== 0 )            //a hits vertical
		{																							  
		
		if (points[a].speed < points[b].speed)
		{
		points[a].move += 4;
		points[b].move = pointRevertLaw(&points[a]);
		}
		else
		{
			points[a].move=pointRevertLaw(&points[a]);
			points[b].move= points[a].move;

		}

	}

}

void point2ColisionAsymetric(void)						   
{
	short speed1, speed2, a, b, x,y;

	
	if (PPCollisionAsymetric())                                  // point 1 (a) hits point 2 (b) by diagonal
		pointRevertLaw(&points[a]);
	    
}

// for three point 3




void SolveUsingRevert (void)
{
	if (P3ColisionCase3Move())               // using simulation
	{
		SetSystemFlag ();
		revert3();
	}

	if (CollisionPixelBound ())
		revert3();
	if (TwoPointsHitThirdByDiagonal())
		revert3();

}
															// without free cell conflict
void SolveOneLineCollision (void)                        // a point and c point are end points,  point b is midlle point

{

	short a,b,c;
	if ( AllPointsInSame() )  
	{ 
		pointRevertLaw(&points[a]);
	    pointRevertLaw(&points[c]);
		if (maxSpeed() == points[c].speed && points[a].move == points[b].move)
			pointRevertLaw(&points[b]);
		else
			if (maxSpeed() == points[a].speed && points[b].move == points[c].move)
			pointRevertLaw(&points[b]); 
	}



}

															   
void SolveOneLineCollision_FreeCell (void)                    // a point and c point are end points,  point b is midlle point; with  free cell conflict

{

	short a,b,c;
					                //  if ( point a and  point b ) are in conflict, using simulation (a,b)  b revert if c max ??
		if ( AllPointsInSame_FreeCell ) 
		{
		
		SetSystemFlag ();
		pointRevertLaw(&points[a]);
	    pointRevertLaw(&points[c]);
		if (maxSpeed() == points[c].speed && points[a].move == points[b].move)
			pointRevertLaw(&points[b]);
		else
			if (maxSpeed() == points[a].speed && points[b].move == points[c].move)
			pointRevertLaw(&points[b]);
		}


}


void CornerSolve()								   // new SOLVE !!!
{
	short a,b,c;                                // (point a  and point b ) are in conflict , point c hits a 
	if (Corner())
	{
	 	points[c].move += 4;
		points[a].move = pointRevertLaw(&points[c]);

	}
}

 


void CornerSolve_FreeCell()
{												// using simulation
	short a,b,c;                            // ( point a and point b ) are in conflict, point c (vertical move) hits a, after collision c and a move by diagonal
	if (Corner_FreeCell())
	{
		if (maxSpeed() = points[c].speed)
		{
			points[c].move += 4;
			points[a].move = pointRevertLaw(&points[c]);
			 SetSystemFlag();
		}
		 
	}
}

// CASE  when all points have different direction  UNRESOLVED ???


void PointsWithDifferentDirectionSolve (void)
{
	short a,b,c; 

	if (AnyPointHitsOtherWithDifferentDirection() )   //a hits vertical  b, b hits horizontal c
													// a invert your direction by diagolal, b with revert a direction, c in same direction						
	{

			points[a].move += 4;
			points[b].move = pointRevertLaw(&points[a]);
	}

}








